#include "endval.h"
namespace smil
{
    endval::endval()
    {
    };
    endval::~endval()
    {
    };
    duration endval::resolve()
    {
        switch (type) {
            case END_INDEFINITE:
                return duration(SYNC_INDEFINITE);
            case END_OFFSET:
                if (element) { // sanity check
                    if (negative) return (element->get_syncbase() - offset);
                    else return (element->get_syncbase() + offset);
                };
            case END_SYNCBASE:
                if (element) { // sanity check
                    if (sync_end) {
                        if (negative) return (element->get_end() - offset);
                        else return (element->get_end() + offset);
                    }
                    else {
                        if (negative) return (element->get_begin() - offset);
                        else return (element->get_begin() + offset);
                    };
                };
            default:
            return duration(SYNC_UNRESOLVED); // unsupported endtypes are unresolved!
        }
    };
}
